<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%
request.setCharacterEncoding("UTF-8");
String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>个人中心</title>
<script type="text/javascript" src="/resource/js/jquery-3.2.1.js"></script>
<script type="text/javascript" src="/resource/js/bootstrap.js"></script>
<link rel="stylesheet" href="/resource/css/bootstrap.css">
	<link rel="stylesheet" href="/resource/kindeditor/themes/default/default.css" />
	<link rel="stylesheet" href="/resource/kindeditor/plugins/code/prettify.css" />
	<script charset="utf-8" src="/resource/kindeditor/kindeditor.js"></script>
	<script charset="utf-8" src="/resource/kindeditor/lang/zh-CN.js"></script>
	<script charset="utf-8" src="/resource/kindeditor/plugins/code/prettify.js"></script>
	<script>
		KindEditor.ready(function(K) {
			window.editor1 = K.create('textarea[name="content1"]', {
				cssPath : '/resource/kindeditor/plugins/code/prettify.css',
				uploadJson : '/resource/kindeditor/jsp/upload_json.jsp',
				fileManagerJson : '/resource/kindeditor/jsp/file_manager_json.jsp',
				allowFileManager : true,
				afterCreate : function() {
					var self = this;
					K.ctrl(document, 13, function() {
						self.sync();
						document.forms['example'].submit();
					});
					K.ctrl(self.edit.doc, 13, function() {
						self.sync();
						document.forms['example'].submit();
					});
				}
			});
			prettyPrint();
		});
	</script>
</head>
<body>
	
	<div class="container">
		<!-- 上方展示区 -->
		<div>
			<br>
			<a href="/">
				<img alt="" src="/resource/pic/logo-admin.jpg">个人中心 
			</a>
			
			<div class="float-right align-items-center" >
				<!-- 右侧的个人中心和退出按钮 -->
				<!-- 如果已经登录，则显示个人中心和退出 -->
					<c:if test="${LOGIN_USER!=null }">
						你好，<b>${LOGIN_USER.nickname }</b>
						<input class="btn btn-primary btn-sm" type="button" onclick="toCenter()" value="${LOGIN_USER.role==0?'个人中心':'管理员中心' }">
						<input class="btn btn-primary btn-sm" type="button" onclick="logout()" value="退出">
					</c:if>
					
					<!-- 如果没有登录，则显示登录和注册按钮 -->
					<c:if test="${LOGIN_USER==null }">
						<input class="btn btn-primary btn-sm" type="button" onclick="toLogin()" value="登录">
						<input class="btn btn-primary btn-sm" type="button" onclick="toReg()" value="注册">
					</c:if>
			</div><br>
		</div>
		<hr>
		
		<!-- 下方展示区 -->
		<div class="row">
			<!-- 左侧导航 -->
			<div class="col-md-2">
			
				<div class="list-group text-center">
				  <a href="#" class="list-group-item list-group-item-action active"
				  data="/my/articles" >我的文章</a>
				  
				  <a href="#" class="list-group-item list-group-item-action" 
				  data="/my/publish">发布文章</a>
				  
				  <a href="#" class="list-group-item list-group-item-action"
				  data="/my/collect">我的收藏</a>
				  
				  <a href="#" class="list-group-item list-group-item-action"
				  >我的评论</a>
				</div>
			</div>
			
			<!-- 右侧页面展示 -->
			<div class="col-md-10">
				<div id="center">
					
				</div>
			</div>
		</div>
	
	</div>
	
</body>
<script type="text/javascript">
	//使用文档就绪函数，
	$(function(){
		
		//加载"我的文章"页面
		$("#center").load("/my/articles");
		
		//绑定超链接事件
		$("a").click(function(){
			//获取标签中的data属性
			var url = $(this).attr("data");
			
			//加载对应页面
			$("#center").load(url);
			
			//将原来选中的变成未选中
			$(".active").removeClass("active");
			
			//修改class属性，实现选中状态
			$(this).addClass("active");
			
		})
	})
	
	//跳转到登录页面
	function toLogin(){
		location="/user/toLogin";
	}
	//跳转到注册页面
	function toReg(){
		location="/user/toRegister";
	}
	//注销
	function logout(){
		location="/user/logout";
	}
	//跳转到个人中心
	function toCenter(){
		var role = "${LOGIN_USER.role}";
		
		//如果为0 则跳转到个人中心，如果为1，则跳转到管理员中心，否则跳转到首页
		if(role != null && role == 0){
			location="/my/";
		}else if(role !=null && role==1){
			location="/admin/";
		}else{
			location="/";
		}
	}
</script>
</html>

<%!
private String htmlspecialchars(String str) {
	str = str.replaceAll("&", "&amp;");
	str = str.replaceAll("<", "&lt;");
	str = str.replaceAll(">", "&gt;");
	str = str.replaceAll("\"", "&quot;");
	return str;
}
%>